package scp;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.InputStreamReader; 

import ch.ethz.ssh2.Connection; 
import ch.ethz.ssh2.SCPClient; 
import ch.ethz.ssh2.SFTPv3Client; 
import ch.ethz.ssh2.Session; 
import ch.ethz.ssh2.StreamGobbler; 

public class Scp { 
public static void main(String[] args)   
    {   
        String user = "root";   
        String pass = "apnring";   
        String host = "192.168.100.123";   
           
        Connection con = new Connection(host);   
        try {   
            con.connect();   
            boolean isAuthed = con.authenticateWithPassword(user, pass);   
            System.out.println("isAuthed===="+isAuthed);   
               
               
            SCPClient scpClient = con.createSCPClient();   
            scpClient.put("D:\\123\\123.txt", "/app"); //�ӱ��ظ����ļ���Զ��Ŀ¼   
//            scpClient.get("/app/systemtool","D:/123/systemtool");  //��Զ�̻�ȡ�ļ�  
            
//            scpClient.put("D:\\apache-tomcat-6.0.29\\webapps\\recursor\\WEB-INF\\serverfile\\192.168.2.190\\policy\\strategy-baddomain.conf", "/root/testor"); //�ӱ��ظ����ļ���Զ��Ŀ¼   

//               
//            SFTPv3Client sftpClient = new SFTPv3Client(con);   
//            sftpClient.mkdir("newRemoteDir", 6);    //Զ���½�Ŀ¼   
//            sftpClient.rmdir("");                   //Զ��ɾ��Ŀ¼   
//               
//            sftpClient.createFile("newRemoteFile"); //Զ���½��ļ�   
//            sftpClient.openFileRW("remoteFile");    //Զ�̴��ļ����ɽ��ж�д   
//               
//            Session session = con.openSession();   
//            session.execCommand("uname -a && date && uptime && who");   //Զ��ִ������   
//               
//               
//               
//            //��ʾִ����������Ϣ   
//            System.out.println("Here is some information about the remote host:");   
//            InputStream stdout = new StreamGobbler(session.getStdout());   
//  
//            BufferedReader br = new BufferedReader(new InputStreamReader(stdout));   
//  
//            while (true)   
//            {   
//                String line = br.readLine();   
//                if (line == null)   
//                    break;   
//                System.out.println(line);   
//            }   
//  
            /* Show exit status, if available (otherwise "null") */  
  
//            System.out.println("ExitCode: " + session.getExitStatus());   
  
//            session.close();   
            con.close();   
        } catch (IOException e) {   
            e.printStackTrace();   
        }   
           
    } 
}